package com.mercury.ec.module.air.dal.mysql.demandorder;

import com.mercury.ec.framework.common.pojo.PageResult;
import com.mercury.ec.framework.mybatis.core.mapper.BaseMapperX;
import com.mercury.ec.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.mercury.ec.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.mercury.ec.module.air.controller.admin.demandorder.vo.demandprice.AirDemandPricePageReqVO;
import com.mercury.ec.module.air.controller.admin.demandorder.vo.demandprice.AirDemandPriceRespVO;
import com.mercury.ec.module.air.dal.dataobject.demandorder.AirDemandPriceDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 机票需求订单方案价格 Mapper
 *
 * @author hesx
 */
@Mapper
public interface AirDemandPriceMapper extends BaseMapperX<AirDemandPriceDO> {

    default PageResult<AirDemandPriceDO> selectPage(AirDemandPricePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AirDemandPriceDO>()
                .eqIfPresent(AirDemandPriceDO::getDemandId, reqVO.getDemandId())
                .eqIfPresent(AirDemandPriceDO::getDemandSchemeId, reqVO.getDemandSchemeId())
                .eqIfPresent(AirDemandPriceDO::getDemandRouteId, reqVO.getDemandRouteId())
                .eqIfPresent(AirDemandPriceDO::getPassengerType, reqVO.getPassengerType())
                .eqIfPresent(AirDemandPriceDO::getPurchaseAdditionalFee, reqVO.getPurchaseAdditionalFee())
                .eqIfPresent(AirDemandPriceDO::getPurchaseServiceFee, reqVO.getPurchaseServiceFee())
                .eqIfPresent(AirDemandPriceDO::getPurchaseTicketPrice, reqVO.getPurchaseTicketPrice())
                .eqIfPresent(AirDemandPriceDO::getPurchasePrice, reqVO.getPurchasePrice())
                .eqIfPresent(AirDemandPriceDO::getPurchaseAirportTax, reqVO.getPurchaseAirportTax())
                .eqIfPresent(AirDemandPriceDO::getPurchaseOilTax, reqVO.getPurchaseOilTax())
                .eqIfPresent(AirDemandPriceDO::getPurchaseTax, reqVO.getPurchaseTax())
                .eqIfPresent(AirDemandPriceDO::getPurchaseAgencyFeeRate, reqVO.getPurchaseAgencyFeeRate())
                .eqIfPresent(AirDemandPriceDO::getPurchaseAgencyFee, reqVO.getPurchaseAgencyFee())
                .eqIfPresent(AirDemandPriceDO::getPurchaseBackRebateFeeRate, reqVO.getPurchaseBackRebateFeeRate())
                .eqIfPresent(AirDemandPriceDO::getPurchaseBackRebateFee, reqVO.getPurchaseBackRebateFee())
                .eqIfPresent(AirDemandPriceDO::getPurchasePrizePrice, reqVO.getPurchasePrizePrice())
                .eqIfPresent(AirDemandPriceDO::getPurchasePrizeTax, reqVO.getPurchasePrizeTax())
                .eqIfPresent(AirDemandPriceDO::getPurchaseAmount, reqVO.getPurchaseAmount())
                .eqIfPresent(AirDemandPriceDO::getPurchasePayable, reqVO.getPurchasePayable())
                .betweenIfPresent(AirDemandPriceDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AirDemandPriceDO::getId));
    }

    default List<AirDemandPriceRespVO> selectByDemandId(Long demandId) {
        return selectJoinList(AirDemandPriceRespVO.class, new MPJLambdaWrapperX<AirDemandPriceDO>()
                .eq(AirDemandPriceDO::getDemandId, demandId)
                .selectAll(AirDemandPriceDO.class)
        );
    }

    default int deleteByDemandId(Long demandId) {
        return delete(AirDemandPriceDO::getDemandId, demandId);
    }
}
